package cn.house.houseai.mapper;

import cn.house.houseai.entify.Device;
import cn.house.houseai.entify.Sensors;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author 羡y
 * @date 2024/9/30
 * @Description
 */
@Mapper
public interface SensorsMapper {
    //查询当前设备使用的传感器
    @Select("SELECT s.sensor_id, s.device_id, s.sensor_type, s.data_collection_time, s.temperature, s.humidity, s.motion_status, s.light_intensity, s.smoke_detected " +
            "FROM sensors s " +
            "JOIN devices d ON s.device_id = d.device_id " +
            "WHERE s.device_id = #{deviceId}")
    List<Sensors> querySensorsByUserId(Integer deviceId);




    /**
     * 当前设备添加传感器数据
     * @param sensors
     * @return
     */
    @Insert("INSERT INTO sensors (device_id, sensor_type, temperature, humidity, motion_status, light_intensity, smoke_detected,data_collection_time) " +
            "VALUES (#{device_id}, #{sensors.sensor_type}, #{sensors.temperature}, #{sensors.humidity}, " +
            "#{sensors.motion_status}, #{sensors.light_intensity}, #{sensors.smoke_detected},#{sensors.data_collection_time})")
    int insertSensors(@Param("device_id") int device_id, @Param("sensors") Sensors sensors);



    /**
     * 用户修改设备的传感器数据
     * @param sensor
     * @return
     */
    int updateSensors( @Param("deviceId") Integer deviceId, @Param("sensorId") Integer sensorId, @Param("sensor") Sensors sensor);


}
